//
//  HWUpdateAppView.m
//  嗨文
//
//  Created by 响当当 on 7/1/19.
//  Copyright © 2019 dongzheng. All rights reserved.
//

#import "HWUpdateAppView.h"

static HWUpdateAppView *alertUpDateView = nil;

@interface HWUpdateAppView()
@property (nonatomic, strong)UIImageView *imageView;
@end

@implementation HWUpdateAppView

+ (HWUpdateAppView *)alertUpDateView
{
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        if (!alertUpDateView) {
            CGRect frame = CGRectMake(0, 0, SCREEN_WIDTH, KScreenHeight);
            alertUpDateView = [[HWUpdateAppView alloc]initWithFrame:frame];
        }
    });
    return alertUpDateView;
}

- (UIImageView *)imageView
{
    if (!_imageView)
    {
        _imageView = [[UIImageView alloc]initWithFrame:CGRectMake(50*kUIScaleBasePlus,100*kUIScaleBasePlus,274*kUIScaleBasePlus,468*kUIScaleBasePlus)];
        _imageView.image = [UIImage imageNamed:@"updateApp"];
        
        UIButton *btn = [HWUtilties creatButtonWithFrame:CGRectMake(SCREEN_WIDTH/2-60*kUIScaleBasePlus,400*kUIScaleBasePlus,120*kUIScaleBasePlus,48*kUIScaleBasePlus)
                                            textAligment:NSTextAlignmentCenter
                                                    text:@"立即更新"
                                                textClor:[UIColor whiteColor]
                                               buttonBGC:JSAMainColor
                                                textFont:15*kUIScaleBasePlus
                                                  target:self
                                                  method:@selector(updateApp)];
        [self addSubview:btn];
    }
    return _imageView;
}

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self)
    {
        self.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.75];
        [self addSubview:self.imageView];
        
    }
    return self;
}


- (void)updateApp
{
    [self removeFromSuperview];
    NSString *url = @"itms-apps://itunes.apple.com/cn/app/id1448659738?mt=8";
    [HWUtilties openUrlSchedule:url];
}

@end
